﻿using eye2;
using System.Windows.Forms;
namespace Module_Debug.Hardware
{
    public class EYE2_402
    {
        public double Lv_eye2_402 = 0.0;
        public double sx_eye2_402 = 0.0;
        public double sy_eye2_402 = 0.0;
        public double X_eye2_402 = 0.0;
        public double Y_eye2_402 = 0.0;
        public double Z_eye2_402 = 0.0;
        public double T_eye2_402 = 0.0;
        public double duv_eye2_402 = 0.0;
        public double JEITA_eye2_402 = 0.0;
        public double FMA_eye2_402 = 0.0;
        //display mode
        const int MODE_Lvxy = 0;
        const int MODE_Tduv = 1;
        const int MODE_Lvduv = 5;
        const int MODE_FMA = 6;
        const int MODE_XYZ = 7;
        const int MODE_JEITA = 8;
        const int MODE_lvPeld = 9;
        const int MODE_Waveform = 10;
        const int MODE_Contrast_flocker = 11;
        //AveragingMode
        const int SLOW = 0;
        const int FAST = 1;
        const int LTD_AUTO = 2;
        const int AUTO = 3;
        //synchronization mode
        const int NTSC = 0;
        const int PAL = 1;
        const int EXTERNAL = 2;
        const int UNIVERSAL = 3;
        const int INTERNAL = 4;
        const int MANUAL = 5;

        private JCEYE2 EYE;
        private bool m_bIsOpen = false;
        private byte casdk_mode = 0;

        public void EYE2_402_DefaultSetting()
        {
            EYE = new JCEYE2();
        }
        public void EYE2_402_AutoConnect()
        {
            EYE = new JCEYE2();
            string[] portList = EYE.GetPortlist();
            bool rel = EYE.Connect(portList[0]);
            if (rel)
            {
                ;
            }
            else
            {
                MessageBox.Show("未发现EYE2_402探头设备！");
            }
        }
        public void EYE2_402_Close()
        {
            bool rel = EYE.DisConnect();
        }

        public void EYE2_402_Measure()
        {
            bool rel = EYE.Measure();
            try
            {
                switch (casdk_mode)
                {
                    case 0: //MODE_Lvxy
                        {
                            sx_eye2_402 = EYE.x;
                            sy_eye2_402 = EYE.y;
                            Lv_eye2_402 = EYE.Lv;
                        }
                        break;
                    case 1:  //MODE_Tduv
                        {
                            X_eye2_402 = EYE.Lv;
                            Y_eye2_402 = EYE.tcp;
                            Z_eye2_402 = EYE.duv;
                        }
                        break;
                    case 8: //MODE_JEITA
                        {
                            JEITA_eye2_402 = EYE.flicker;
                        }
                        break;
                    default:
                        break;
                }
            }
            catch
            {
                MessageBox.Show("测量失败！");
            }
        }
        public int eye2_402_speed = 1;//默认Fast
        public void EYE2_402_SingleCalibration(byte MODE, byte channel, double freq_set)
        {
            m_bIsOpen = true;
            EYE.SetChannel(channel);
            EYE.SetMeasureMode(MODE);//xyLv//
            EYE.SetSyncSpeedMode(INTERNAL, freq_set.ToString(), eye2_402_speed);//sync mode and frequency
            EYE.ZeroCalibration();
        }

        public void rb_XYZ()
        {
            bool rel = EYE.SetMeasureMode(7);
        }

        public void rb_FMA()
        {
            bool rel = EYE.SetMeasureMode(6);
        }

        public void rb_Tcpduv()
        {
            bool rel = EYE.SetMeasureMode(1);
        }

    }

}
